<?php
class News_model extends CI_Model {

    public function __construct()
    {
        $this->load->database();
        $this->load->library('session');
    }
    public function get_news($rows,$page)
    {
        $this->db->order_by('id', 'DESC');
        $this->db->limit($rows,($page-1)*10);
        $query = $this->db->get('ims_punch_images');
        return $query->result_array();
    }
    public function total_news(){
        $query = $this->db->get('ims_punch_images');
        return $num = $query->num_rows();
    }
    public function get_new($id) {
        $this->db->where('id',$id);
        $query = $this->db->get('ims_punch_images');
        return $query->result_array();
    }
    public function delete_new($id)
    {
        $this->db->where('id',$id);
        $this->db->delete('ims_punch_images');
    }
    public function save_news($data)
    {

        if($this->db->where('id',$data['id'])){
            $this->db->replace('ims_punch_images',$data);
        }else{
            $this->db->insert('ims_punch_images', $data);
        }
    }
    public function ims_punch_cat($id){
        $this->db->where('parent_id',$id);
        $query = $this->db->get('ims_punch_cat');
        return $query->result_array();
    }
}